package com.kurancy.authentication.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class FacebookConfig {
	
	@Value("${${KURANCY_ENV}.facebook.secret}")
    private String secret; // = "551bb54b2820eec1989169c0e8d5b8fe";
	
	@Value("${${KURANCY_ENV}.facebook.client.id}")
    private String client_id; // = "148487568608874"; 

    // set this to your servlet URL for the authentication servlet/filter
	@Value("${${KURANCY_ENV}.facebook.kurancy.redirect.uri}")
    private String kurancy_redirect_uri; // = "http://localhost:8080/fbauth";
	
	
    /// set this to the list of extended permissions you want
	@Value("${${KURANCY_ENV}.facebook.extended.permissions}")
    private String perms; // = new String[] {"publish_stream", "email"};
	
	@Value("${${KURANCY_ENV}.facebook.graph.authorize.base}")
	private String facebookGraphAuthorizeBase;
	
	@Value("${${KURANCY_ENV}.facebook.graph.access.token.base}")
	private String facebookGraphAccessTokenBase;

    public String getSecret() {
        return secret;
    }

    public String getLoginRedirectURL() {
//        return "https://graph.facebook.com/oauth/authorize?client_id=" +
//            client_id + "&display=page&redirect_uri=" +
//            redirect_uri+"&scope="+perms;
    	return facebookGraphAuthorizeBase + "?client_id=" + client_id + "&display=page&redirect_uri=" + kurancy_redirect_uri + "&scope="+ perms;
    }

    public String getAuthURL(String authCode) {
//        return "https://graph.facebook.com/oauth/access_token?client_id=" +
//            client_id+"&redirect_uri=" +
//            redirect_uri+"&client_secret="+secret+"&code="+authCode;
    	
    	return facebookGraphAccessTokenBase + "?client_id=" + client_id+"&redirect_uri=" + kurancy_redirect_uri + "&client_secret=" + secret + "&code=" + authCode;
    }
}